package com.road.vast.company.controller;


import com.road.vast.common.entity.Result;
import com.road.vast.common.entity.ResultCode;
import com.road.vast.company.service.CoCompanyService;
import com.road.vast.pojo.company.CoCompany;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 郭泽鹏
 * @since 2020-06-30
 */
@RestController
@RequestMapping("/company")
public class CoCompanyController {
    @Resource
    private CoCompanyService coCompanyService;

    @PostMapping("")
    public Result add(@RequestBody CoCompany coCompany){
        coCompanyService.add(coCompany);
        return new Result(ResultCode.SUCCESS);
    }

    //改
    @PutMapping("/{id}")
    public Result updateCoCompany(@PathVariable(value = "id") String id, @RequestBody CoCompany coCompany){
        coCompany.setId(id);
        coCompanyService.updateCoCompany(coCompany);
        return new Result(ResultCode.SUCCESS);
    }

    //删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(value = "id") String id){
        coCompanyService.delete(id);
        return new Result(ResultCode.SUCCESS);
    }

    //查
    @GetMapping("/{id}")
    public Result findById(@PathVariable(value = "id") String id){
        CoCompany coCompany = coCompanyService.findById(id);
        Result result = new Result(ResultCode.SUCCESS);
        result.setData(coCompany);
        return result;
    }

    @GetMapping("")
    public Result findAll(){
        List<CoCompany> list = coCompanyService.findAll();
        Result result = new Result(ResultCode.SUCCESS);
        result.setData(list);
        return result;
    }

    /**
     * 审核通过
     */
    @PutMapping("audit/{id}")
    public Result audit(@PathVariable(value = "id") String id){
        coCompanyService.updateAuditState(id);
        return new Result(ResultCode.SUCCESS);
    }

    /**
     * 审核不通过
     */
    @PutMapping("refuse/{id}")
    public Result refuse(@PathVariable(value = "id") String id){
        coCompanyService.updateRefuse(id);
        return new Result(ResultCode.SUCCESS);
    }
}

